package main

import (
	"gitee.com/extrame/tujiang/http"
	"gitee.com/extrame/tujiang/http/ctrl"
	"gitee.com/extrame/tujiang/http/ctrl/admin"
	"gitee.com/extrame/tujiang/http/model"
	"gitee.com/extrame/tujiang/ocr"
	"github.com/extrame/goblet"
	"github.com/extrame/goblet/plugin"
	"github.com/sirupsen/logrus"

	//import mordenc sqlite
	_ "modernc.org/sqlite"
)

var (
	confFile     string
	image        string
	imageDir     string
	useServering bool
	port         string
	debug        bool
)

// func init() {
// 	flag.StringVar(&confFile, "config", "config/conf.yaml", "config from ocr system. If not given, will use default config.")
// 	flag.StringVar(&image, "image", "", "image to predict. if not given, will use image_dir")
// 	flag.StringVar(&imageDir, "image_dir", "", "imgs in dir to be predicted. if not given, will check servering")
// 	flag.BoolVar(&useServering, "use_servering", false, "whether to use ocr server. [default: false]")
// 	flag.StringVar(&port, "port", "18600", "which port to serve ocr server. [default: 18600].")
// 	flag.BoolVar(&debug, "debug", false, "whether to use debug mode. [default: false]")
// }

func main() {

	server := goblet.Organize("tujiang", plugin.StandardJsonWrapper(plugin.SjwWithSuccessCode(0)), plugin.JWT())

	var ocrConfig ocr.Config
	var httpConfig http.Config
	server.AddConfig("paddle", &ocrConfig)
	server.AddConfig("http", &httpConfig)

	logrus.Info("Starting OCR server with config...", ocrConfig)
	if debug {
		logrus.SetLevel(logrus.DebugLevel)
	}

	sys := ocr.NewOCRSystem(&ocrConfig)

	logrus.Info("OCR system has been initialized.", sys)

	server.ControlBy(&ctrl.Ocr{
		System: sys,
	})
	server.ControlBy(&admin.User{
		Config: &httpConfig,
	})
	server.ControlBy(&admin.System{
		Config: &httpConfig,
	})

	server.AddModel(&model.User{})

	server.Run()
}
